package com.gyms.animotion;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.os.Handler;
import android.widget.ImageView;


/**
 * Created by ltx on 17/8/18
 * 收藏的动画
 */

public class CollectAnimotion {
    private Handler mHandler;
    private ImageView mIvCollect;

    public CollectAnimotion(Handler mHandler,ImageView mIvCollect) {
        this.mHandler = mHandler;
        this.mIvCollect = mIvCollect;
    }


    private Runnable mRunnable=new Runnable() {
        @Override
        public void run() {
            doAnimotion(mIvCollect);
            mHandler.postDelayed(mRunnable, 4000);
        }
    };

    private  void doAnimotion(ImageView mIvCollect){
        ObjectAnimator mScaleXAnimator=ObjectAnimator.ofFloat(mIvCollect,"scaleX",1f,1.35f,1f,1.2f,1f);
        ObjectAnimator mScaleYAnimator=ObjectAnimator.ofFloat(mIvCollect,"scaleY",1f,1.35f,1f,1.2f,1f);
        // 步骤2：创建组合动画的对象
        AnimatorSet animSet = new AnimatorSet();
        animSet.play(mScaleXAnimator).with(mScaleYAnimator);
        animSet.setDuration(1200);
        animSet.start();
    }


    public void startAnimotion(){
        mHandler.postDelayed(mRunnable, 1000);
    }

    public void stopAnimotion(){
        mHandler.removeCallbacksAndMessages(null);
    }
}
